﻿using System;
using System.IO;
using System.Data;
using System.Text;
using System.Diagnostics;
using System.Security;
using System.Security.Cryptography;


namespace KeepPwdPcInput
{
    class SHA256
    {
        public string SHA256Encrypt(string strIN)
        {
            //string strIN = getstrIN(strIN);
            byte[] tmpByte;
            SHA256Managed sha256 = new SHA256Managed();

            tmpByte = sha256.ComputeHash(GetKeyByteArray(strIN));
            sha256.Clear();
            return bytes2Hex(tmpByte);

        }

        private byte[] GetKeyByteArray(string strKey)
        {
            UTF8Encoding Asc = new UTF8Encoding();

            return Asc.GetBytes(strKey);
        }

        public static String bytes2Hex(byte[] bts)
        {
            String des = "";
            String tmp = null;
            for (int i = 0; i < bts.Length; i++)
            {
                tmp = Convert.ToString(bts[i] & 0xFF, 16);
                if (tmp.Length == 1)
                {
                    des += "0";
                }
                des += tmp;
            }
            return des;
        }
    }
}
